<?php
// +---------------------------------------------------------------------------+
// | This file is part of the KnowledgebasePublisher package                   |
// | KnowledgebasePublisher - web based knowledgebase publisher tool           |
// |                                                                           |
// | Author:  Evgeny Leontev <eleontev@gmail.com>                              |
// | Copyright (c) 2005 Evgeny Leontev                                         |
// |                                                                           |
// | For the full copyright and license information, please view the LICENSE   |
// | file that was distributed with this source code.                          |
// +---------------------------------------------------------------------------+

class KBEntry extends AppObj
{
	
	var $properties = array('id'		 		=> NULL,
							'author_id' 		=> '',
							'updater_id'		=> '',
							'title'	 			=> '',
							'body' 				=> '',
							'date_posted'		=> '',
							//'date_updated'	=> '',
							'meta_keywords'		=> '',
							'meta_description'	=> '',
							'url_title' 		=> '',
							'hits'				=> 0,
							'sort_order'		=> 'sort_end',
							'private'			=> 0,
							'active'			=> 1
							);
	
	var $hidden = array('id', 'author_id', 'updater_id', 'date_posted', 'hits');
	var $category = array();
	var $category_mirror = array();	
	var $attachment = array();
	var $related = array();
	var $member_role = array();
	
	
	function setCategoryMirror($val) {
		$this->category_mirror = &$val;
	}
	
	function &getCategoryMirror() {
		return $this->category_mirror;
	}
	
	function setCategory($val) {
		$this->category = &$val;
	}
	
	function &getCategory() {
		return $this->category;
	}
	
	function getMemberRole() {
		return $this->member_role;
	}
	
	function setMemberRole($role) {
		$this->member_role = $role;
	}
	
	function setAttachment($val) {
		$this->attachment = &$val;
	}
	
	function &getAttachment() {
		return $this->attachment;
	}

	function setRelated($val) {
		$this->related = &$val;
	}
	
	function &getRelated() {
		return $this->related;
	}	
	
	
	function _callBack($property, $val) {
		if($property == 'date_posted' && !$val) {
			$val = date('Y-m-d H:i:s');
		
		} elseif($property == 'author_id' && !$val) {
			$val = $_SESSION['member_']['user_id'];
		
		} elseif($property == 'updater_id') {
			$val = $_SESSION['member_']['user_id'];
		
		} elseif($property == 'active' && !$val) {
			$val = 0;
		}  		
		return $val;
	}
	
	
	function validate($values) {
		
		require_once 'eleontev/Validator.php';
		
		$required = array('title', 'body', 'category');
		
		$v =& new Validator($values, false);

		// check for required first, return errors
		$v->requiredArray('required_msg', $required);
		if($v->getErrors()) {
			$this->errors =& $v->getErrors();
			return true;
		}
	}
}
?>